<!--
 * @Author: your name
 * @Date: 2020-04-17 17:02:39
 * @LastEditTime: 2020-06-18 11:02:33
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \v-nw-h5\src\components\wx\WxShareBody.vue
 -->
<template>
    <div>
<!--        <wx-show-menu></wx-show-menu>-->
    </div>
</template>
<script>
import WxSharePubQrcode from './WxSharePubQrcode'

let wx = require('weixin-js-sdk');
import XWxConfig from '../../x/XWxConfig'

export default {
    data () {
        return {
            giveChannel: '0',
            identityType: 0,
            identityKey: 0,
            defaultShareBody: {
                shareType: 0,
                title: "您的好友邀请您一起参加活动",
                photo: this.staticImageUrl('images/index/nvWa_logo.png'),
                content: '您的好友邀请您一起参加活动',
                link: window.location.href
            },
        }
    },
    props: {
        shareBody: {
            type: Object
        },
        storeId: {
            type: String
        },

    },
    mounted () {
        if(this.v_is_weixin){
            let shareBody = this.shareBody ? this.shareBody : this.defaultShareBody;
            this.init(shareBody);
        }
    },
    methods: {
         async init (shareBody) {
            let that = this;
            let wxConfig = await XWxConfig.getConfig();
            if (wxConfig) {
                wx.config(wxConfig);
                wx.ready(() => {
                    //分享给朋友
                    if (!!wx.updateAppMessageShareData) {
                        wx.updateAppMessageShareData({
                            title: that.defaultShareBody.title, // 分享标题
                            link: that.defaultShareBody.link, // 分享链接
                            imgUrl:  that.defaultShareBody.imgUrl, // 分享图标
                            desc:  that.defaultShareBody.content, // 分享描述
                        });
                    } else {
                        wx.onMenuShareAppMessage({
                            title: that.defaultShareBody.title, // 分享标题
                            link: that.defaultShareBody.link, // 分享链接
                            imgUrl:  that.defaultShareBody.imgUrl, // 分享图标
                            desc:  that.defaultShareBody.content, // 分享描述
                        })
                    }
                    //分享到朋友圈
                    if (!!wx.updateTimelineShareData) {
                        wx.updateTimelineShareData({
                            title: that.defaultShareBody.title, // 分享标题
                            link: that.defaultShareBody.link, // 分享链接
                            imgUrl:  that.defaultShareBody.imgUrl, // 分享图标
                            fail(data){
                                console.log('failData',data)
                            },
                        });
                    } else {
                        wx.onMenuShareTimeline({
                            title: that.defaultShareBody.title, // 分享标题
                            link: that.defaultShareBody.link, // 分享链接
                            imgUrl:  that.defaultShareBody.imgUrl, // 分享图标
                        })
                    }
                    wx.checkJsApi({
                        jsApiList: wxConfig.jsApiList, // 需要检测的JS接口列表，所有JS接口列表见附录2,
                        success: function (res) {
                            console.log(res,'checkJsApi');
                            // 以键值对的形式返回，可用的api值true，不可用为false
                            // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
                            // alert("check js api -- " + JSON.stringify(res))
                        }
                    });
                });
                wx.error(function (res) {
                    console.log(res, "wx验证失败！")
                });
            }
        },
    },
    watch: {},
    components: {
        // 'wx-show-menu': () => import('./WxShowMenu'),
    }
}

</script>
<style scoped>
</style>
